package com.example.gcmtest1.youtube;

import java.io.Serializable;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

import android.database.Cursor;
import android.util.Log;

public class YoutubeSQLRecord implements Serializable {

	private String logName = "YoutubeSQLRecord";
	
	private long _id = -1;
	private String _originalUrl;
	private String _title;
	private String _contentType;
	private long _contentLength;
	private String _fileLocation;
	private String _finalUrl;
	private long _lastByte;
	private int _status;
	
	
	public YoutubeSQLRecord() {
		
	}
	
	public static YoutubeSQLRecord cursorToRecord(Cursor cursor) {
		YoutubeSQLRecord r = new YoutubeSQLRecord();
		
		r.setId(cursor.getLong(0));
		r.setOriginalUrl(cursor.getString(1));
		r.setTitle(cursor.getString(2));
		r.setContentType(cursor.getString(3));
		r.setContentLength(cursor.getLong(4));
		r.setLastByte(cursor.getLong(5));
		r.setFileLocation(cursor.getString(6));
		r.setFinalUrl(cursor.getString(7));
		r.setStatus(cursor.getInt(8));
				
		return(r);
	}
	
	public int getStatus() {
		return(this._status);
	}
	
	public void setStatus(int status) {
		this._status = status;
	}
	
	public void setLastByte(long lastByte) {
		this._lastByte = lastByte;
	}
	
	public long getLastByte() {
		return(this._lastByte);
	}
	
	public void setFinalUrl(String finalUrl) {
		this._finalUrl = finalUrl;
	}
	
	public String getFinalUrl() {
		return(this._finalUrl);
	}
	
	public void setFileLocation(String fileLocation) {
		this._fileLocation = fileLocation;
	}
	
	public String getFileLocation() {
		return(this._fileLocation);
	}
	
	public void setContentLength(long contentLength) {
		this._contentLength = contentLength;
	}
	
	public long getContentLength() {
		return(this._contentLength);
	}
	
	public void setContentType(String contentType) {
		this._contentType = contentType;
	}
	
	public String getContentType() {
		return(this._contentType);
	}
	
	public void setId(long id) {
		this._id = id;
	}
	
	public long getId() {
		return(this._id);
	}
	
	public void setOriginalUrl(String originalUrl) {
		this._originalUrl = originalUrl;
	}
	
	public String getOriginalUrl() {
		return(this._originalUrl);
	}
	
	public void setTitle(String title) {
		this._title = title;
	}
	
	public String getTitle() {
		return(this._title);
	}
	
	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		
		/*
		sb.append("id=" + String.valueOf(this._id));
		sb.append(", contentLength=" + String.valueOf(this._contentLength));
		sb.append(", lastByte=" + String.valueOf(this._lastByte));
		*/
		int i = 0;
		
		for (Method m : this.getClass().getDeclaredMethods()) {
			
			if (Modifier.isPublic(m.getModifiers())) {
				
				if (m.getName().startsWith("get")) {
					try {
						//Log.d(logName, m.getName());
						
						Object obj = m.invoke(this, (Object[]) null);
						String value = "{null}";
						if (obj != null) value = obj.toString();
						
						if (i > 0) {
							sb.append(", ");
						}
						
						sb.append(m.getName() + "=" + value);
						
						i++;
					} catch (Exception e) {
						//e.printStackTrace();
					}	
				}
								
			}
		}
		
		return(sb.toString());
	}
}
